package controller.validator;

import entity.Section;
import exception.InputValidationErrors;

/**
 * Implements validation for adding, updating or deleting cart items.
 * 
 * @author huangjm.2012, jaslin.wee.2012
 * 
 */
public class CartValidator extends Validator {

	private String courseCode;
	private String sectionCode;

	private Section section;
	private String userId;

	public Section getSection() {
		return section;
	}

	public String getUserId() {
		return userId;
	}

	public CartValidator(String courseCode, String sectionCode, String userId) {
		this.courseCode = courseCode;
		this.sectionCode = sectionCode;
		this.userId = userId;
	}

	@Override
	public void performValidationBeforeAdding() throws InputValidationErrors {

		try {
			checkForPreRequisitesCompletion(userId, courseCode);

			this.section = sectionMgr
					.retrieveSectionForCourseCodeAndSectionCode(courseCode,
							sectionCode);

		} catch (Exception e) {
			throw new InputValidationErrors(e.getMessage());
		}

	}

	@Override
	public void performValidationBeforeUpdating() throws InputValidationErrors {
		// TODO Auto-generated method stub

	}

	@Override
	public void performValidationBeforeDeleting() throws InputValidationErrors {
		// TODO Auto-generated method stub

	}

}
